package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCarMapper {
    /**
     * 条件查询当前商品是否存在购物车中
     * @param shoppingCart
     * @return
     */
    public ShoppingCart queryCart(ShoppingCart shoppingCart);

    /**
     * 修改商品的数量
     * @param shoppingCart
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    public void updateCartNum(ShoppingCart shoppingCart );

    /**
     * 新增商品
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    public void insertCart(ShoppingCart shoppingCart);

    /**
     * 查询购物车
     * select * from shopping_cart where user_id=#{} order by create_time desc
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId} order by create_time desc")
    public List<ShoppingCart> list(Long userId);


    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    public void clean(Long userId);
}
